Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
Each time I push new data to the array of object, the name property becomes "undefined"

Below is the class in which I try to push new data to the array of objects

 static addCustomer(input) {
        // buyTicket
        let data = Model.readCustomer();
        let theaterId = Number(input[0]);
        let name = input[1];
        let gender = input[2];
        let seatNumber = input[3];
        let ticketType = input[4];
        let custId = 1;
        let theaterName = "xxi";
        let movie = "movie";
    
        if (data.length !== 0) {
          custId = data[data.length - 1].id + 1;
        }
    
        switch (theaterId) {
          case 1:
            theaterName = "Cinema 12";
            movie = "Codezilla";
            break;
          case 2:
            theaterName = "Bioskop IXX";
            movie = "The Journey to Center of OOP";
            break;
          case 3:
            theaterName = "Moviemaxx";
            movie = "Avatar The Legend of Callback";
            break;
          case 4:
            theaterName = "VGCinema";
            movie = "Git The Kungfu Master";
            break;
          case 5:
            theaterName = "Bioskop IXX";
            movie = "Json The Protector";
            break;
    
          default:
            break;
        }
    
        let newCustomer = new Customer(
          custId,
          name,
          gender,
          new Ticket(theaterName, ticketType, movie, seatNumber)
        );
    
        data.push(newCustomer)
        console.log(data)
      }

This is the console.log result, you notice that the name property of the previous data becomes "undefined" each time I try to push new data to the array.

screenshot

Below is my "Customer" class in which I import to the models.js file

class Customer {
  constructor(id, customerName, gender, ticket) {
    this.id = id;
    this.customerName = customerName;
    this.gender = gender;
    this.ticket = new Ticket(
      ticket.theaterName,
      ticket.type,
      ticket.movie,
      ticket.seatNumber
    );
  }
}

class Ticket {
  constructor(theaterName, type, movie, seatNumber) {
    this.theaterName = theaterName;
    this.type = type;
    this.movie = movie;
    this.seatNumber = seatNumber;
  }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda